import numpy as np
import pandas as pd
famille_pandas = [
np.array([50, 2.5, 10, 40]),
np.array([100, 5, 20, 80]),
np.array([110, 6, 22, 80])
]
famille_pandas_numpy = np.array(famille_pandas)
famille_pandas_numpy
array([[ 50. , 2.5, 10. , 40. ], [100. , 5. , 20. , 80. ], [110. , 6. , 22. , 80. ]])
famille_pandas_numpy[:, 0]
array([ 50., 100., 110.])
famille_pandas_numpy[:]
array([[ 50. , 2.5, 10. , 40. ], [100. , 5. , 20. , 80. ], [110. , 6. , 22. , 80. ]])
famille_pandas_numpy[:4]
array([[ 50. , 2.5, 10. , 40. ], [100. , 5. , 20. , 80. ], [110. , 6. , 22. , 80. ]])
data.loc['california']
area 423967.0 pop 38332521.0 Name: california, dtype: float64
def make_df(cols, ind):
"""crée rapidement des DataFrame"""
data = {c: [str(c) + str(i) for i in ind]
for c in cols}
return pd.DataFrame(data, ind)
make_df('ABC', range(3))
A | B | C | |
---|---|---|---|
0 | A0 | B0 | C0 |
1 | A1 | B1 | C1 |
2 | A2 | B2 | C2 |
df1 = make_df('AB', [1, 2])
df2 = make_df('AB', [3, 4])
pd.concat([df1, df2])
A | B | |
---|---|---|
1 | A1 | B1 |
2 | A2 | B2 |
3 | A3 | B3 |
4 | A4 | B4 |
# les noms, le departement et la date d'entrée
df1 = pd.DataFrame({'employee': ['Bob', 'Jake', 'Lisa', 'Sue'],
'department': ['Accounting', 'Engenineering', 'Engenineering', 'HR']})
df2 = pd.DataFrame({'employee': ['Lisa', 'Bob', 'Jake', 'Sue'],
'date': [2004, 2008, 2012, 2014]})
df3 = pd.merge(df1, df2)
df3
employee | department | date | |
---|---|---|---|
0 | Bob | Accounting | 2008 |
1 | Jake | Engenineering | 2012 |
2 | Lisa | Engenineering | 2004 |
3 | Sue | HR | 2014 |
df4 = pd.DataFrame({'department': ['Accounting', 'Engenineering', 'HR'],
'supervisor':['carly', 'Guido', 'Steve']})
pd.merge(df3, df4)
employee | department | date | supervisor | |
---|---|---|---|---|
0 | Bob | Accounting | 2008 | carly |
1 | Jake | Engenineering | 2012 | Guido |
2 | Lisa | Engenineering | 2004 | Guido |
3 | Sue | HR | 2014 | Steve |
df5 = pd.DataFrame({'department': ['Accounting', 'Accounting',
'Engineering', 'Engineering', 'HR','HR'],
'competence': ['math', 'spreadsheets', 'coding','linux',
'spreadsheets', 'organization']})
pd.merge(df1, df5)
employee | department | competence | |
---|---|---|---|
0 | Bob | Accounting | math |
1 | Bob | Accounting | spreadsheets |
2 | Sue | HR | spreadsheets |
3 | Sue | HR | organization |